#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> m;

        for (int i = 0; i < strs.size(); i++) {
            string s = strs[i];
            // 将字符串排序作为 key
            sort(s.begin(), s.end());
            m[s].push_back(strs[i]);
        }

        vector<vector<string>> v;

        for (auto it = m.begin(); it != m.end(); ++it) {
            v.push_back(it->second);
        }
    
        return v;
    }
};